Preserve queued browser event identity across account changes#161
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThe browser tracker now flushes queued events before attribution identity changes or clearing. Identity comparisons normalize email and trim identifiers, while tests verify previous and subsequent event payload identities. ChangesBrowser identity batch boundaries
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant Outlit
participant Fetch
Caller->>Outlit: identify(previous identity)
Caller->>Outlit: track(event)
Caller->>Outlit: identify(new identity)
Outlit->>Fetch: flush queued event with previous identity
Outlit->>Outlit: update current identity
Caller->>Outlit: clearUser()
Outlit->>Fetch: flush queued events with known identity
Outlit->>Outlit: clear identity state
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/browser/__tests__/unit/tracker.test.ts (1)
203-274: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a test for
hasAttributionChanged's normalization logic.Both new tests use clearly distinct identities, so the trim/case-insensitive-email normalization added in
hasAttributionChanged(tracker.ts lines 371-378) is untested. Worth adding a case verifying that re-identifying with the same email in different casing/whitespace (or same trimmed userId/customerId) does not trigger an extra flush/attribution change.it("does not flush when identify is called with the same normalized identity", async () => { const outlit = new Outlit({ publicKey: "pk_test", autoTrack: false, trackPageviews: false, trackForms: false, trackEngagement: false }) outlit.enableTracking() outlit.identify({ email: "User-A@Example.com " }) await outlit.flush() outlit.track("same_identity_event") outlit.identify({ email: " user-a@example.com" }) // same identity, different case/whitespace await outlit.flush() const payloads = vi.mocked(global.fetch).mock.calls.map(([, options]) => JSON.parse(String(options?.body))) // Expect the track event and the re-identify to batch together in one flush call, // rather than being split by an unnecessary attribution-change flush. expect(payloads).toHaveLength(2) })🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/browser/__tests__/unit/tracker.test.ts` around lines 203 - 274, Add a test in the tracker unit-test suite covering hasAttributionChanged normalization: identify with an email containing different casing and surrounding whitespace, queue an event, then identify the same normalized email and flush. Assert no extra attribution-change flush occurs by verifying both actions remain in the expected single post-initial-identification payload, while preserving the existing distinct-identity tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/browser/__tests__/unit/tracker.test.ts`:
- Around line 203-274: Add a test in the tracker unit-test suite covering
hasAttributionChanged normalization: identify with an email containing different
casing and surrounding whitespace, queue an event, then identify the same
normalized email and flush. Assert no extra attribution-change flush occurs by
verifying both actions remain in the expected single post-initial-identification
payload, while preserving the existing distinct-identity tests.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 19b17f31-cabc-4841-a44a-2fd8da94f701
📒 Files selected for processing (3)
.changeset/browser-identity-batch-boundaries.mdpackages/browser/__tests__/unit/tracker.test.tspackages/browser/src/tracker.ts
Summary
Verification
Summary by CodeRabbit
Bug Fixes
Tests